package com.project.service.impl;

import com.project.bean.Car;
import com.project.mapper.ICarMapper;
import com.project.service.ICarService;
import com.project.service.impl.BaseService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class CarServiceImpl extends BaseService implements ICarService {
    @Override
    public List<Car> findAll() {
        SqlSession session = this.getSession();
        ICarMapper mapper = session.getMapper(ICarMapper.class);
        List<Car> list = mapper.findAll();

        session.close();
        return list;
    }

    @Override
    public void add(Car car) {
        SqlSession session = this.getSession();
        ICarMapper mapper = session.getMapper(ICarMapper.class);
        mapper.add(car);

        session.commit();
        session.close();
    }

    @Override
    public Car findById(int id) {
        SqlSession session = this.getSession();
        ICarMapper mapper = session.getMapper(ICarMapper.class);
        Car car = mapper.findById(id);
        session.close();
        return car;
    }
}
